class Solution:
    def checkInclusion(self, s1: str, s2: str) -> bool:
        s = s2
        t = s1
        need = collections.defaultdict(int)
        window = collections.defaultdict(int)
        
        for char in t:
             need[char] += 1
             
        left, right = 0, 0
        valid = 0
        
        while right < len(s):
            c = s[right]
            
            if c in need:
                window[c] += 1
                if window[c] == need[c]:
                    valid += 1
            
            right += 1
        
            while right - left == len(t):
                # 当滑动窗口的大小跟目标字符串长短一致时，就是缩减窗口时机 
                
                if valid == len(need):
                    # 滑动窗口大小和目标字符串长度一样前提下，有效字符也一样长，就是找到了
                    return True

                d = s[left]
                
                if d in need:
                    if window[d] == need[d]:
                        valid -= 1
                    window[d] -= 1
                
                left += 1
        return False